//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;

namespace Eas.WebCrawler.PlugIns.UrlEnumerators {

    /// <summary>A helper class that provides an enumeration of starting <see cref="Uri"/>s from a file where each line in the file is a uri or a comment (where the line starts with <code>//</code>).</summary>
    public static class FileBasedUrlEnumerator {

        /// <summary>Reads Uris out of a collection of files and returns them.</summary>
        /// <param name="files">The files containing the Uris.</param>
        /// <returns>An enumeration of the Uris in the files.</returns>
        /// <remarks>The syntax for these files is very simple.  Each line must contain one Uri and nothing else, or the line must be a comment.  Comments are lines where the first two characters in the line make up a C++ style single-line comment(i.e. <code>//</code>).</remarks>
        public static IEnumerable<string> GetStartingUris(params string[] files) {
            List<string> uris= new List<string>();
            foreach (string file in files) {
                foreach(string line in Eas.WebCrawler.Common.IO.TextLineEnumerator.Create(file, true, true)){
                    if((!string.IsNullOrEmpty(line)) && (!line.StartsWith("//", StringComparison.Ordinal))){
                        uris.Add(line);
                    }
                }
            }
            return uris;
        }
    }
}
